import { getSpreadQrCode } from '@/services/system/user';
import { useModel } from '@umijs/max';
import { Image, message } from 'antd';
import React, { useCallback, useEffect, useState } from 'react';

const boxClassName = {
  width: '100%',
  background: '#fff',
  padding: '30px 0px 100px 0px',
  textAlign: 'center',
};

const Settings: React.FC = () => {
  let [imgUrl, setImgUrl] = useState('');
  const { initialState } = useModel('@@initialState');
  const { currentUser } = initialState || {};
  const getImgUlr = useCallback(async () => {
    if (currentUser.tenantId) {
      getSpreadQrCode(currentUser.tenantId).then((res) => {
        if (res.code === 200) {
          setImgUrl(res.data);
        } else {
          message.error(res.msg);
        }
      });
    }
  }, []);
  useEffect(() => {
    getImgUlr();
  });

  return (
    <div style={boxClassName}>
      <h4 style={{ marginBottom: '30px' }}>推广二维码</h4>
      <Image
        src={imgUrl}
        width={200}
        height={200}
        preview={false}
        fallback=""
      ></Image>
    </div>
  );
};

export default Settings;
